//
//  HHDetailsViewController.m
//  YSJ
//
//  Created by 花花 on 2016/12/16.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "HHDetailsViewController.h"
#import "HHDetailCell.h"
#import "HHButton.h"
#import "UIBarButtonItem+HHExtension.h"
@interface HHDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) NSMutableArray *btnsArr;
@property(nonatomic, strong) UIView *bottomView;
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSArray *DataArr;
//
@property(nonatomic, copy) NSString *detaText;



@end

static NSString *const detaCellID = @"detaCellID";
static NSString *const CellID = @"CellID";
@implementation HHDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupNav];
    
    [self setupTableView];


    
}

-(void)setupNav{
    
    
    self.title = @"商品详情";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor colorWithHexString:ThemeColor]};
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"YSShare_end" highImage:@"YSShare_end" target:self action:@selector(shareOnClick)]     ;

    


}

-(void)shareOnClick{

    HHLog(@"%s",__func__);

}

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];

}


- (void)setupTableView{

    
    UITableView *tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, screen_width, screen_height) style:UITableViewStyleGrouped];
    
    
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, screen_width, 300)];
    tableView.tableHeaderView = view;
    [tableView registerNib:[UINib nibWithNibName:NSStringFromClass([HHDetailCell class]) bundle:nil] forCellReuseIdentifier:detaCellID];
    
    tableView.dataSource= self;
    tableView.delegate= self;
    
    
    [self.view addSubview:tableView];
    _tableView = tableView;
    
}
-(NSArray *)DataArr{
    
    if (!_DataArr) {
        _DataArr =  @[@"秋日限定 小小居家酒",@"产品详情",@"商品评价",@"物流信息",@"联系客服"];
    }
    
    return _DataArr;
    
}

#pragma mark - <UITableViewDataSource,UITableViewDelegate>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return 6;

}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if (indexPath.row == 0) {
        HHDetailCell *cell =[tableView dequeueReusableCellWithIdentifier:detaCellID];
        return cell;
    }else{
        UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellID];
        
        if (!cell) {
            cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellID];
        }
        
        if(indexPath.row == 1){
        
            cell.textLabel.text = @"化开一勺醇香的鸭油";
        
            cell.textLabel.textColor =[UIColor grayColor];
        }else if (indexPath.row ==2){
        cell.textLabel.text = @"产品详细";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        }else if (indexPath.row ==3){
            cell.textLabel.text = @"商品评价";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        
        }else if (indexPath.row ==4){
        
            cell.textLabel.text = @"物流信息";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        }else{
            
             cell.textLabel.text = @"联系客服";
            
            cell.detailTextLabel.text = @"4006-277-717";
            _detaText = cell.detailTextLabel.text;
                    }

        
        return cell;
    
    }
    
    return nil;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if (indexPath.row ==5) {
        
        NSString *phone =[_detaText stringByReplacingOccurrencesOfString:@"-" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, _detaText.length)];
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]];
        [[UIApplication sharedApplication] openURL:url];
   
    }



}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    if (indexPath.row == 0 || indexPath.row == 1) {
        return 60;
    }
    return 50;
}




@end
